<?php

require_once ABSPATH . '/system/sql.php';
require_once ABSPATH . '/system/token.php';

$sql_link = MySQL::getInstance();

$res = $sql_link->prepare('SELECT pass,name FROM users WHERE username=:username');
$res->bindParam(':username',$_GET['username']);
$res->execute();
$data = $res->fetch(PDO::FETCH_ASSOC);

if( (! empty($data)) && password_verify($_GET['pass'],$data['pass'])){
    $token = token_get($_GET['username']);
    $ret = array(
        'code' => 200,
        'msg' => 'ok',
        'data' => array(
            'token' => $token,
            'user' => array(
                'name' => $data['name'],
            ),
        ),
    );
    echo json_encode($ret);
}else{
    require_once __DIR__.'/403.php';
}


/*
{
	"code": 200,
	"msg": "ok",
	"data": {
        "token":"nepadmin-token-test",
        "user":{
            "username":"小明"
        }
    }
}*/